import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post, Put,
  Query,
  Req,
} from '@nestjs/common';
import { UserService } from '@/modules/user/user.service';
import { User } from '@/modules/user/user.entity';
import { wrapperResponse } from '@/utils';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('info')
  getUserByToken(@Req() req) {
    return wrapperResponse(
      this.userService.findByUsername(req.user.username),
      '获取用户信息成功',
    );
  }

  @Get('/profile')
  getUserProfile(@Query() query) {
    return wrapperResponse(
      this.userService.findProfile(query.id),
      '获取用户详细信息成功',
    );
  }

  @Get('/logs')
  getUserLogs(@Query() query) {
    return wrapperResponse(
      this.userService.findUserLogs(query.id),
      '获取用户日志成功',
    );
  }

  @Get('/getLogsByGroup')
  getLogsByGroup(@Query() query) {
    return wrapperResponse(
      this.userService.findLogsByGroup(query.id),
      '根据请求状态分组',
    );
  }

  @Get('/:id')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.userService.findOne(id);
  }

  @Get()
  findAll(): Promise<User[]> {
    return this.userService.findAll();
  }

  @Post()
  create(@Body() body) {
    return this.userService.create(body);
  }

  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.userService.remove(id);
  }

  @Put()
  updateUser(@Body() body) {
    return this.userService.update(body.id, body)
  }

}
